#include <iostream>

using namespace std;

//Declare a RGB888 structure
typedef struct RGB888
{
	char r;
	char g;
	char b;
}RGB888;

//Function
//Purpose: Convert color from RGB 888 to RGB 565
//Return: an unsigned short value, contain 16 bit of RGB 565 
unsigned short ConvertRgb888ToRgb565 (RGB888 _color);

int main ()
{
	//Sample color
	RGB888 rgb888_color;
	rgb888_color.r = 128;
	rgb888_color.g = 128;
	rgb888_color.b = 255;

	unsigned short rgb565_color = ConvertRgb888ToRgb565 (rgb888_color);
	cout << rgb565_color;

	cin.get ();
	 
	return 0;
}

unsigned short ConvertRgb888ToRgb565 (RGB888 _color)
{
	short result_color;

	char temp1, temp2, temp3;
	temp1 = (_color.r & 0xFF) >> 3;
	temp2 = (_color.g & 0xFF) >> 2;
	temp3 = (_color.b & 0xFF) >> 3;

	result_color = ((temp1 << 11) | (temp2 << 5) | (temp3));

	return result_color;
}